package org.duang.db.sql.ds;

import java.util.Map;

import javax.sql.DataSource;

import org.duang.db.Connection;

public abstract class AbstractDataSource<T extends DataSource> implements IDataSourceFactory{

	@Override
	public T getDataSource(Map<String, String> map) throws Exception {
		T ds = builderDataSource();
		setUsername(ds, map.get(Connection.USERNAME_FIELD));
		setPassword(ds, map.get(Connection.PASSWORD_FIELD));
		setUrl(ds, map.get(Connection.URL_FIELD));
		setInitParam(ds, map); 
		return ds;
	}
	

	public abstract T builderDataSource();
	public abstract void setUsername(T ds, String userName);
	public abstract void setPassword(T ds, String password);
	public abstract void setUrl(T ds, String jdbcUrl);
	public abstract void setInitParam(T ds, Map<String, String> map);
	
}
